{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 媒体内容审核 VCR\n",
    "1、导入待审核视频，VCR 支持两种导入方式：本地文件导入、BOS 地址导入。\n",
    "\n",
    "* 本地文件导入：您需要先指定本地视频上传后存储本地视频的BOS 地址，如果还未创建BOS Bucket，请参考 BOS 操作指南创建，存储 BOS 地域仅支持北京，然后选择本地音视频（最多支持批量上传20个音视频），最后选择审核模板并且可根据需要选择通知，点击确定则发起审核。\n",
    "* BOS 地址导入：对象存储 BOS 地域仅支持北京，选择BOS 中 Bucket 路径以及Bucket下待审核音视频（最多支持批量导入20个音视频），然后选择审核模板并且可根据需要选择通知，点击确定则发起审核。\n",
    "\n",
    "> 输入限制\n",
    "\n",
    "* 文件格式：3gpp,asf/wmv,avi,flv/f4v,mkv,mov/mp4/m4a,mp3,mp2,mpeg/mpg,ts/ogg,mts,wmv/wma,rm/rmvb,webm等\n",
    "* 视频编码标准：H.264,H.263/H.263+,MPEG-1/2/4,VP8/9,Quicktime,RealVideo,WMV,MJPEG等\n",
    "* 音频编码标准：MP1，MP2,MP3,AAC,AC-3,WMA,PCM,ADPCM,AMR,RealAudio,Vorbis,DSD等\n",
    "\n",
    "2、视频审核，审核过程中可以查看当前审核状态。控制台支持根据不同条件筛选审核视频。\n",
    "\n",
    "* 审核状态处于排队中，可以取消审核。\n",
    "* 审核结束状态（包括审核完成和审核失败），可以发起重新审核。\n",
    "* 审核失败时，将鼠标放在『审核失败』旁的图标上，可以看到审核失败原因。\n",
    "* 审核完成时，可以查看审核结果。\n",
    "\n",
    "3、查看审核结果。\n",
    "\n",
    "在视频审核列表页，审核完成的视频可以点击『查看结果』，进入视频审核详情页查看内容。\n",
    "\n",
    "> 机审结果正常\n",
    "\n",
    "机审结果正常，判断该视频没有问题可直接上架。\n",
    "\n",
    "> 机审结果违规\n",
    "\n",
    "机审确认结果：机器判断视频违规，不需人审进行二次确认，可直接封禁/下架，置信度高。\n",
    "机审疑似结果：机器判断该视频有可能违规，需要人审进行二次确认，置信度低。\n",
    "视频机审结果违规时，视频审核详情页会显示机审确认结果和机审疑似结果的具体信息，包括审核结果所属的审核场景、审核类型和审核项，还包括置信度、物料类型、审核证据和时间位置等信息。 \n",
    "\n",
    "### 接口\n",
    "请求语法  \n",
    "'''  \n",
    "PUT /v<version>/media HTTP/1.1  \n",
    "host: vcr.bj.baidubce.com  \n",
    "authorization: <bce-authorization-string>  \n",
    "x-bce-date: <bce-authorization-utc-date>  \n",
    "content-type: application/json  \n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 审核 BOS 视频\n",
    "PUT /v1/media HTTP/1.1\n",
    "host: vcr.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n",
    "x-bce-date: <bce-authorization-utc-date>\n",
    "\n",
    "{\n",
    "  \"source\": \"bos://testbucket/dir/video.mp4\",\n",
    "  \"preset\": \"ad_preset\",\n",
    "  \"notification\": \"vcr_callback\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 审核 VOD 媒资原视频\n",
    "PUT /v1/media HTTP/1.1\n",
    "host: vcr.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n",
    "x-bce-date: <bce-authorization-utc-date>\n",
    "\n",
    "{\n",
    "  \"source\": \"vod://mda-fhepatsnpn4rk9z\",\n",
    "  \"notification\": \"vcr_callback\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 审核 VOD 转码后视频\n",
    "\n",
    "PUT /v1/media HTTP/1.1\n",
    "host: vcr.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n",
    "x-bce-date: <bce-authorization-utc-date>\n",
    "\n",
    "{\n",
    "  \"source\": \"vod://mda-fhepatsnpn4rk9z-mp4\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 审核 URL 视频\n",
    "\n",
    "PUT /v1/media HTTP/1.1\n",
    "host: vcr.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n",
    "x-bce-date: <bce-authorization-utc-date>\n",
    "\n",
    "{\n",
    "  \"source\": \"http://test.domain.com/dir/video.mp4\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 审核包含鉴权参数的 URL 视频\n",
    "\n",
    "PUT /v1/media HTTP/1.1\n",
    "host: vcr.bj.baidubce.com\n",
    "content-type: application/json\n",
    "authorization: <bce-authorization-string>\n",
    "x-bce-date: <bce-authorization-utc-date>\n",
    "\n",
    "{\n",
    "  \"source\": \"http://test.domain.com/dir/video.mp4\",\n",
    "  \"auth\": \"token=abcxyz&timestamp=1514993900\"\n",
    "}    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "HTTP/1.1 200 OK\n",
    "{\n",
    "    \"source\": \"vod://mda-fhepatsnpn4rk9z\",\n",
    "    \"status\": \"FINISHED\",\n",
    "    \"createTime\": \"2017-03-22T12:00:00Z\",\n",
    "    \"finishTime\": \"2017-03-22T12:06:48\",\n",
    "    \"label\": \"REVIEW\",\n",
    "    \"results\": [{\n",
    "        \"type\": \"sexual_porn\",\n",
    "        \"items\": [{\n",
    "            \"subType\": \"behavior\",\n",
    "            \"target\": \"audio\",\n",
    "            \"startTimeInSeconds\": 0,\n",
    "            \"confidence\": 68,\n",
    "            \"label\": \"REVIEW\"\n",
    "        }]\n",
    "    },\n",
    "    {\n",
    "        \"type\": \"ad_brand\",\n",
    "        \"items\": [\n",
    "            {\n",
    "                \"confidence\": 99.66,\n",
    "                \"evidence\": {\n",
    "                    \"location\": {\n",
    "                        \"heightInPixel\": 15,\n",
    "                        \"leftOffsetInPixel\": 386,\n",
    "                        \"topOffsetInPixel\": 111,\n",
    "                        \"widthInPixel\": 35\n",
    "                    },\n",
    "                    \"thumbnail\": \"http://path.to.thumbnail.jpg\"\n",
    "                },\n",
    "                \"extra\": \"美孚\",\n",
    "                \"label\": \"REJECT\",\n",
    "                \"subType\": \"brand\",\n",
    "                \"target\": \"thumbnail\",\n",
    "                \"timeInSeconds\": 845\n",
    "            },\n",
    "            {\n",
    "                \"confidence\": 90.06,\n",
    "                \"evidence\": {\n",
    "                    \"location\": {\n",
    "                        \"heightInPixel\": 24,\n",
    "                        \"leftOffsetInPixel\": 451,\n",
    "                        \"topOffsetInPixel\": 132,\n",
    "                        \"widthInPixel\": 103\n",
    "                    },\n",
    "                    \"thumbnail\": \"http://path.to.thumbnail.jpg\"\n",
    "                },\n",
    "                \"extra\": \"诺优能\",\n",
    "                \"label\": \"REVIEW\",\n",
    "                \"subType\": \"brand\",\n",
    "                \"target\": \"thumbnail\",\n",
    "                \"timeInSeconds\": 219\n",
    "            }]\n",
    "    },\n",
    "    {\n",
    "        \"type\": \"political_group\",\n",
    "        \"items\": [\n",
    "            {\n",
    "                \"confidence\": 99.8,\n",
    "                \"endTimeInSeconds\": 4226,\n",
    "                \"evidence\": {\n",
    "                    \"text\": \"昆明市工商局的\"\n",
    "                },\n",
    "                \"extra\": \"工商局\",\n",
    "                \"label\": \"REJECT\",\n",
    "                \"startTimeInSeconds\": 4225,\n",
    "                \"subType\": \"political_group_positive\",\n",
    "                \"target\": \"speech\"\n",
    "            }]\n",
    "    }]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "{\n",
    "    \"label\" : \"REJECT\",\n",
    "    \"results\" : [{\n",
    "        \"type\": \"sexual_porn\",\n",
    "        \"items\": [{\n",
    "            \"subType\": \"products\",\n",
    "            \"target\": \"thumbnail\",\n",
    "            \"timeInSeconds\": 103,\n",
    "            \"confidence\": 98.76,\n",
    "            \"label\": \"REJECT\",\n",
    "            \"evidence\": {\n",
    "                \"thumbnail\": \"http://xxx/xxx.jpg\"\n",
    "            }\n",
    "        }, {\n",
    "            \"subType\": \"behavior\",\n",
    "            \"target\": \"audio\",\n",
    "            \"confidence\": 70,\n",
    "            \"startTimeInSeconds\": 0,\n",
    "            \"label\": \"REVIEW\"\n",
    "        }, {\n",
    "            \"subType\": \"behavior\",\n",
    "            \"target\": \"character\",\n",
    "            \"confidence\": 69,\n",
    "            \"timeInSeconds\": 2,\n",
    "            \"label\": \"REVIEW\",\n",
    "            \"evidence\": {\n",
    "                \"thumbnail\": \"http://xxx/xxx.jpg\",\n",
    "                \"location\": {\n",
    "                    \"leftOffsetInPixel\": 10,\n",
    "                    \"topOffsetInPixel\": 10,\n",
    "                    \"widthInPixel\": 20,\n",
    "                    \"heightInPixel\": 20\n",
    "                },\n",
    "                \"text\": \"这是一段文字识别的涉黄文字\"\n",
    "            }\n",
    "        }, {\n",
    "            \"subType\": \"behavior\",\n",
    "            \"target\": \"speech\",\n",
    "            \"confidence\": 68,\n",
    "            \"startTimeInSeconds\": 0,\n",
    "            \"endTimeInSeconds\": 20,\n",
    "            \"label\": \"REVIEW\",\n",
    "            \"evidence\": {\n",
    "                \"text\": \"这是一段语音识别的涉黄文字\"\n",
    "            }\n",
    "        }],\n",
    "    }, {\n",
    "        \"type\": \"sexual_sexy\",\n",
    "        \"items\": [{\n",
    "            \"subType\": \"female\",\n",
    "            \"target\": \"thumbnail\",\n",
    "            \"timeInSeconds\": 35,\n",
    "            \"confidence\", 68.4,\n",
    "            \"label\": \"REVIEW\",\n",
    "            \"evidence\": {\n",
    "                \"thumbnail\": \"http://xxx/xxx.jpg\"\n",
    "            }\n",
    "        }]\n",
    "    }, {\n",
    "        \"type\": \"terror_event\",\n",
    "        \"items\": [{\n",
    "            \"subType\": \"explosion\",\n",
    "            \"target\": \"character\",\n",
    "            \"timeInSeconds\": 12,\n",
    "            \"confidence\": 50,\n",
    "            \"label\": \"REVIEW\",\n",
    "            \"extra\": \"炸弹\",\n",
    "            \"evidence\": {\n",
    "                \"thumbnail\": \"http://xxx/xxx.jpg\",\n",
    "                \"location\": {\n",
    "                    \"leftOffsetInPixel\": 10,\n",
    "                    \"topOffsetInPixel\": 10,\n",
    "                    \"widthInPixel\": 20,\n",
    "                    \"heightInPixel\": 20\n",
    "                },\n",
    "                \"text\": \"炸弹是文字识别的暴恐文字\"\n",
    "            }\n",
    "        }]\n",
    "    }, {\n",
    "        \"type\": \"politician\",\n",
    "        \"items\": [{\n",
    "            \"subType\": \"politician_positive\",\n",
    "            \"target\": \"thumbnail\",\n",
    "            \"timeInSeconds\": 144,\n",
    "            \"confidence\": 95,\n",
    "            \"label\": \"REJECT\",\n",
    "            \"extra\": \"习大大\",\n",
    "            \"evidence\": {\n",
    "                \"thumbnail\": \"http://xxx/xxx.jpg\",\n",
    "                \"location\": {\n",
    "                    \"leftOffsetInPixel\": 10,\n",
    "                    \"topOffsetInPixel\": 10,\n",
    "                    \"widthInPixel\": 20,\n",
    "                    \"heightInPixel\": 20\n",
    "                }\n",
    "            },\n",
    "        }]\n",
    "    }, {\n",
    "        \"type\": \"political_group\",\n",
    "        \"items\": [{\n",
    "            \"subType\": \"political_group_positive\",\n",
    "            \"target\": \"speech\",\n",
    "            \"startTimeInSeconds\": 2\n",
    "            \"endTimeInSeconds\": 10\n",
    "            \"confidence\": 90,\n",
    "            \"label\": \"REJECT\",\n",
    "            \"extra\": \"天安门\",\n",
    "            \"evidence\": {\n",
    "                \"text\": \"天安门是语音识别的涉政文字\"\n",
    "            }\n",
    "        }]\n",
    "    }]\n",
    "}\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
